package com.example.springboot.mapper.test01.service;

import com.example.springboot.entity.User;
import com.example.springboot.mapper.test01.mapper.UserMapperTest01;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * UserServiceTest01<br>
 */
@Controller
@Slf4j
public class UserServiceTest01 {
	@Autowired
	private UserMapperTest01 userMapperTest01;

    @Transactional()
	public int insertUser(String name, Integer age) {

        /*
        * PageHelper分页插件
        * */
        PageHelper.startPage(2, 3); // 底层实现原理采用改写语句
        List<User> select = userMapperTest01.select();
//        // 返回给客户端展示
        PageInfo<User> pageInfoUserList = new PageInfo<User>(select);


        int insertUserResult = userMapperTest01.insert(name, age);
		log.info("######insertUserResult:{}##########", insertUserResult);
		int i = 1 / age;
		// 怎么样验证事务开启成功!~
		return insertUserResult;
	}

}
